<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="fselect/fselect.css" />
	</head>

	<body>
		<select name="" id="sel" multiple="multiple">
			<optgroup label="Languages">  
		        <option value="cp">C++</option>  
		        <option value="cs">C#</option>  
		        <option value="oc">Object C</option>  
		        <option value="c">C</option>  
		    </optgroup>  
		</select>
		<button id="get">获取值</button>
		<button id="give">赋值</button>
	</body>
	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<script src="fselect/fselect.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		//js 初始化
		$('#sel').fSelect({
			showSearch:false //关闭搜索
		});
		
		//取值文字
		$('.fs-label').text()

		$("#get").click(function(){
			//取值 value
			var value = [].map.call($('.fs-option.selected'), function(el) {
				return el.dataset.value
			})
			console.log(value);
		})
		var arr = ["cp","cs"];
		$("#give").click(function(){
			$(".fs-option").removeClass("selected");
			$(".fs-label").text(arr.join(","));
			for(var i=0;i<arr.length;i++){
				var this_value = arr[i];
				for(var j=0;j<$(".fs-option").length;j++){
					if($(".fs-option").eq(i).attr("data-value")==this_value){
						$(".fs-option").eq(i).addClass("selected");
					}
				}
			}
		})
	</script>

</html>